var articleList;
var localData =[
    {"id": 1,"articleTitle": "户外啥的乱七八糟1","illustrate":"hw1325481","state":1,"dataTime":'2016-1-12 9:05'},
    {"id": 2,"articleTitle": "户外啥的乱七八糟2","illustrate":"hw1325481","state":0,"dataTime":'2016-1-12 9:05'},
    {"id": 3,"articleTitle": "户外啥的乱七八糟3","illustrate":"hw1325481","state":1,"dataTime":'2016-1-12 9:05'},
    {"id": 4,"articleTitle": "户外啥的乱七八糟4","illustrate":"hw1325481","state":1,"dataTime":'2016-1-12 9:05'}
    ];
$(function () {
    if($('#articleList').length>0){
        articleList = $.fn.bsgrid.init('articleList', {
            localData: localData,   //本地json
            //url:'',               //数据地址
            // autoLoad: false,
            pageSizeSelect: true,
            pageSize: 10,
            stripeRows: true,
            displayBlankRows: false
        });
    }
});
//articleList表格相关方法
var article={
    state:function(record, rowIndex, colIndex, options){
    	var state=articleList.getRecordIndexValue(record, 'state');
        if(state==1) return '<span class="sui-text-success">有效</span>';
        else if(state==0) return '<span class="sui-text-disabled">无效</span>';
    },
    operate:function(record, rowIndex, colIndex, options){
        var id=articleList.getRecordIndexValue(record, 'id');
        var operate='';
        operate+='<a href="articleEdit.html?id=' + id + '">编辑</a> <a href="javascript:;" onclick="article.del(' + id + ')">删除</a>';
        return operate;
    },
    search:function(){
        var form=$("#seach").serializeArray();
        articleList.search(form);
    },
    del:function(id){
        table.del({
            "id":id,
            "url":'../../testApi/dels.php'
        })
    },
    delCheck:function(){
        var ids = articleList.getCheckedValues("id");
        table.delCheck({
            "ids":ids,
            "url":'../../testApi/dels.php'
        })   
    }
}
$("#articleAdd").validate({
    rules:{
        articleTitle:{required:true}
    }
});
$("#articleEdit").validate({
    rules:{
        articleTitle:{required:true}
    }
});
if($("#content").length>0){
    KindEditor.ready(function(k){
        k.create("#content");
    });
}